<?php

namespace App\Console\Commands;

use App\Member;

use App\Repositories\OrderRepository;
use Carbon\Carbon;
use Illuminate\Console\Command;

class PayOrderHanle extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'order:handle';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '处理错误的订单';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $orderRep=new OrderRepository();


        \DB::table('pay_orders')->orderBy('id')->where('created_at','>',Carbon::yesterday())->where('is_pay',0)->chunk(100,function($order) use($orderRep){
            foreach ($order as $v){//找出已支付 但是未执行逻辑的订单

              if($orderRep->searchWechatOrder($v->out_trade_no)){
                  $this->info('错误的订单'.$v->out_trade_no.'\\n');
                  $orderRep->handle(['out_trade_no'=>$v->out_trade_no]);
               }else{
                //  $member=  \App\Http\Controllers\Admin\Member\Repository\Member::find(3);
                 //dd($member);
                  ////$member->notify(new App\Notifications\InvoicePaid('查不到的订单'.$v->out_trade_no) );
                  $this->info($v->out_trade_no.'/n');
              }
            }
        });
            // $orderRep->handle(['out_trade_no'=>'2018051316910']);
    }
}
